<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> 
<%
java.lang.String urlpath = request.getContextPath();
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>任务订单管理</title>
<meta http-equiv="expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<link rel="stylesheet" href="<%=urlpath %>/css/admin_style.css" />
<link rel="stylesheet" href="<%=urlpath %>/css/yu.css" />
<script type="text/javascript" src="<%=urlpath %>/core/core.js"></script>
<script type="text/javascript" src="<%=urlpath %>/js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="<%=urlpath %>/js/pagination.js"></script>
<script type="text/javascript" src="<%=urlpath %>/js/yu.js"></script>
<script type="text/javascript" src="<%=urlpath %>/js/jquery.contextmenu.r2.packed.js"></script>
<script type="text/javascript">
var imgpath = 'images';
//check used
function showselect(type){
	var selects = get_tags(document,'select');
	for (i=0; i<selects.length; i++) {
		selects[i].style.visibility = type;
	}
}
function checkgroupset(chars){
	if (!confirm("确定删除吗? 如果您删除了此代理组,请到站点缓存数据管理更新代理头衔缓冲!")) return false;
	window.location.href = chars;return false;
}
function get_tags(parentobj,tag){
	if (typeof parentobj.getElementsByTagName!='undefined') {
		return parentobj.getElementsByTagName(tag);
	} else if (parentobj.all && parentobj.all.tags) {
		return parentobj.all.tags(tag);
	} else {
		return null;
	}
}
//other function
function atccheck(){
	if(document.FORM.atc_title.value==''){
		alert('标题为空');
		document.FORM.atc_title.focus();
		return false;
	} else if(document.FORM.fid.value==''){
		alert('没有选择文章所属分类');
		document.FORM.fid.focus();
		return false;
	}
	_submit();
}
function level_jump(admin_file){
	var URL=document.mod.selectfid.options[document.mod.selectfid.selectedIndex].value;
	location.href=admin_file+"?adminjob=level&action=editgroup&gid="+URL;
}
function ip_jump(name){
	URL = eval('document.form1.' + name + '.options[document.form1.' + name + '.selectedIndex].value');
	location.href=URL;
}
function pwJsCheck(_this,check,tagName){
	try{
		if (typeof tagName == 'undefined') tagName = "tr";
		if (typeof check == 'undefined') {
			if (typeof _this.checked == 'boolean') {
				check = _this.checked;
			} else {
				check = false;
			}
		}
		var o = _this.parentNode;
		var i = 3;
		while(i--){
			if (o.nodeName.toLowerCase() == tagName) {
				var className =  o.className.replace(/\s?td_bgC/ig, "");
				if (check) {
					className +=' td_bgC';
				}
				o.className = className;
				break;
			} else {
				o = o.parentNode;
			}
		}
	}catch(e){}
}
//Cookies Function
function getCookie(name) {
    var start = document.cookie.indexOf(name + '=');
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start==-1) {
        return null;
    }
    var end = document.cookie.indexOf(';', len);
    if (end == -1) {
        end = document.cookie.length;
    }
    return unescape(document.cookie.substring(len,end));
}
function setCookie(name, value, expires, path, domain, secure) {
	if (!expires) {
		expires = new Date();
		expires.setTime(expires.getTime()+31536000);
	}
	document.cookie = name + '=' + escape(value) +
        ( (expires) ? ';expires=' + expires.toGMTString() : '') +
        'path=' + ( (path) ? path : '/') +
        ( (domain)  ? ';domain=' + domain : '') +
        ( (secure)  ? ';secure' : '');
}

function elementBind(type,id,stylename,csstext){
	var element = document.createElement(type);
	if (id) {
		element.id = id;
	}
	if (typeof(stylename) == 'string') {
		element.className = stylename;
	}
	if (typeof(csstext) == 'string') {
		element.style.cssText = csstext;
	}
	return element;
}
function addChild(parent,type,id,stylename,csstext){
	parent = objCheck(parent);
	var child = elementBind(type,id,stylename,csstext);
	parent.appendChild(child);
	return child;
}

function delElement(id){
	id = objCheck(id);
	id.parentNode.removeChild(id);
}
function objCheck(obj) {
	if (typeof(obj)=='string') {
		obj	= getObj(obj);
	}
	return obj;
}

function shenhe(id){
	$.ajax({
		type:"GET",
		url:"<%=urlpath%>/ajax/auditWeiboIndentFor163",
		dataType:"json",
		data:{indentId:id,base:${baseIndentType.id }},
		success:function(result)
		{
			if(result&&result==1){
				alert("审核成功!");
				location.reload();
			}else{
				alert("审核失败!");
			}
		}
	});

}

function batchShenhe(){
	var msg = "";
	var json = "";
	$(".c1").each(function(i,val){
		msg += "[订单号:"+$(val).attr("indent_id")+",微博名:"+$(val).attr("indent_title")+"]  ";
		json += $(val).attr("indent_id") +",";
	});
	msg += "  将进行审核操作，是否继续？";
	
	ui.confirm(msg,function(z){
        if(z){
            
        	$.ajax({
        		type:"GET",
        		url:"<%=urlpath%>/ajax/batchShenhe",
        		dataType:"json",
        		data:{indentIds:json,base:${baseIndentType.id }},
        		success:function(result)
        		{
        			if(result&&result==1){
        				alert("审核成功!");
        				location.reload();
        			}else{
        				ui.alert("审核失败!");
        			}
        		}
        	});
        	
        	
        }else{
                   
        }
},true);
}

function batchTuikuan(){
	var msg = "";
	var json = "";
	$(".c1").each(function(i,val){
		msg += "[订单号:"+$(val).attr("indent_id")+",微博名:"+$(val).attr("indent_title")+"]  ";
		json += $(val).attr("indent_id") +",";
	});
	msg += "  将进行退款操作，是否继续？";
	
	ui.confirm(msg,function(z){
        if(z){
            
        	$.ajax({
        		type:"GET",
        		url:"<%=urlpath%>/ajax/batchTuikuan",
        		dataType:"json",
        		data:{indentIds:json,base:${baseIndentType.id },state:3},
        		success:function(result)
        		{
        			if(result&&result==1){
        				alert("退款成功!");
        				location.reload();
        			}else{
        				ui.alert("退款失败!");
        			}
        		}
        	});
        	
        	
        }else{
                   
        }
},true);
}

document.onkeydown = function(e){
	var e = is_ie ? window.event: e;
	if ( e.keyCode==116) {
		window.location.reload();
		if (is_ie) {
			e.keyCode = 0;
       		e.cancelBubble = true;
		}
		return false;
	}
}
</script>
<style type="text/css">
.c1{
	background-color: yellow;
}
</style>
</head>
<body>
<div class="wrap">
<div class="nav3 mb10">
	<ul class="cc">
		<li class="current"><a href="${baseIndentType.url2 }">${baseIndentType.name }</a></li>
		<sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_USER,ROLE_USER_2">
		<li><a href="toTaobaoUzAdd?base=${baseIndentType.id }">${baseIndentType.name }订单</a></li>
		
          </sec:authorize>
        <span class="admin_tips" style="margin-left:10px;line-height:22px;font-weight:bold;">您目前余额：<b style="cursor: pointer; height: 25px; line-height: 25px; font-weight: 700; display: inline-block; color: green;" id="fans_a" onclick="openNewUrl('menu_44','充值消费记录','/agent/accountRecordUI!query.action');return false;" title="查看充值消费记录">${curUser.money }</b></span>
    </ul>
</div>
<div class="admin_info mb10">
	<h3 class="h1"><b>提示信息</b></h3>
	<sec:authorize ifNotGranted="ROLE_AUDIT">
	<div class="legend">
		${baseIndentType.pointOut}
	</div>
	</sec:authorize>
</div>
<div class="admin_search">
<form action="taobaoUzManageUIForSearch?base=${baseIndentType.id }" method="post" onsubmit="getQueryString(this,'queryString')" id="queryForm" style="display:none1;">

<h2 class="h1"><b>查询订单</b></h2>
<div class="admin_table mb10">
<table width="100%" cellspacing="0" cellpadding="0">
	<tr class="tr2 vt">
        <td class="td1">订单编号：</td>
		<td class="td2">
       		<input type="text" name="qe.bianhao"/>
        </td>
        
    </tr>
</table>
</div>
<div class="tac mb10">
	<span class="btn"><span><button type="submit">提 交</button></span></span>
</div>
<input type="hidden" name="qe.status" id="qe.status" value="${current }"/>
<input type="hidden" name="queryString" id="queryString" value="qe.bianhao=${qe.bianhao }&qe.status=${current}">

</form>
</div>
<form action="" method="post">
<input type="hidden" name="action" value="editgroup">
<!--<h2 class="h1"><b>订单列表</b></h2>-->
<div class="admin_table mb10">
<div class="tab_A" style="margin-top:16px;">
	<ul style="float:left">
        <li id="state_all" class="current"><a href="javascript:void(0);queryStatus('all');" title="查看全部订单">全部(${paginationSupport.totalCount })</a></li>
           <li id="state_0"><a href="javascript:void(0);queryStatus('0');" title="查看全部订单">排队中(${paginationSupport.shenheCount })</a></li>
           <li id="state_1"><a href="javascript:void(0);queryStatus('1');" title="查看全部订单">正在执行(${paginationSupport.zhixingCount })</a></li>
           <li id="state_3"><a href="javascript:void(0);queryStatus('3');" title="查看全部订单">已退款(${paginationSupport.tuikuanCount })</a></li>
           <li id="state_2"><a href="javascript:void(0);queryStatus('2');" title="查看全部订单">已完成(${paginationSupport.wanchengCount })</a></li>
    
    	   
    	   <sec:authorize ifAnyGranted="ROLE_ROOT,ROLE_ADMIN,ROLE_AUDIT">
				<c:if test="${current=='0' || current=='1'  }">
					<li style="margin-left:150px;"><a href="javascript:void(0);batchShenhe();" title="批量审核:点击需要审核的订单所在行，单击右键全选/反选">批量审核</a></li>
					<li><a href="javascript:void(0);batchTuikuan();" title="批量退款:点击需要退款的订单所在行，单击右键全选/反选">批量退款</a></li>
				</c:if>
		   </sec:authorize>
    </ul>
</div>

<script type="text/javascript">
    function queryStatus($statusCode){
        var statuses=document.getElementsByName("qe.status");
        for(var i=0;i<statuses.length;i++){
            statuses[i].value=$statusCode;
        }
        var form=document.getElementById("queryForm");
        getQueryString(form,'queryString');
        form.submit();
    }
</script>
<table width="100%" cellspacing="0" cellpadding="0" style="margin-top:-8px;">
	<tbody>
      <tr class="tr2 td_bgB">
		<td>序号</td>
        <td>订单编号</td>
		<td>目标</td>
		<td>进度</td>
		<td>初始数量</td>
		<td>类型</td>
		<!--<td>执行时间</td>
		<td>地区</td>-->
		<td>订单状态</td>
		<td>执行时间</td>
		<sec:authorize ifNotGranted="ROLE_AUDIT">
        <td>订单费用</td>
        </sec:authorize>
        <td>操作</td>
	</tr>
	<c:forEach var='indent' items='${paginationSupport.items}' varStatus='u'  step='1'>
		<tr class="tr1 vt con_menu" indent_title="${indent.targetTitle }" indent_id="${indent.id }" c="0">
          <td class="td2">${u.index+1}</td>
          <td class="td2"><b>${indent.id }</b></td>
		  <td class="td2"  style="height:18px;"><a href="${indent.targetUrl }" target="_blank">${indent.targetTitle }</a></td>
		  <td class="td2" style="font-weight:bold;"><font color="green">${indent.nowNumber-indent.startNumber }</font>/<font color="blue">${indent.number }</font></td>
          <td class="td2">
              ${indent.startNumber }
          </td>
          <td class="td2">${indent.baseIndentType.name }</td>
		  <!--<td class="td2">自动</td>
		  <td class="td2">随机</td>-->
          <td class="td2">
          <c:if test="${indent.state==0 }">
          	<span style="color:red;">排队中</span>
          </c:if>
          <c:if test="${indent.state==1 }">
          	<span style="color:blue;">执行中……</span>
          </c:if>
          <c:if test="${indent.state==2 }">
          	<span style="color:green;">已完成√</span>
          </c:if>
          <c:if test="${indent.state==3 }">
          	<span style="color:red;">已退款×</span>
          </c:if>
          </td>
          <td class="td2">下单时间：<font color="green">${indent.createDate }</font><br>结束时间：<font color="blue">${indent.endDate }</font></td>
          <sec:authorize ifAnyGranted="ROLE_ROOT,ROLE_ADMIN,ROLE_USER,ROLE_USER_2">
          	<td class="td2">${indent.totalPrice }元</td>
          </sec:authorize>
          <td class="td2">
             <sec:authorize ifAnyGranted="ROLE_ROOT,ROLE_ADMIN,ROLE_AUDIT">
             	<c:if test="${indent.state==0 }">
          			<a href="#" onclick="shenhe(${indent.id });">审核</a><br/>
          			<a href="toTaobaoUzIndentRefund?userIndent.id=${indent.id }" target="_self">退款</a><br/>
          		</c:if>
          		<c:if test="${indent.state==1 }">
          			<a href="toTaobaoUzIndentRefund?userIndent.id=${indent.id }" target="_self">退款</a><br/>
          		</c:if>
             </sec:authorize>
             <sec:authorize ifAnyGranted="ROLE_ROOT,ROLE_ADMIN">
             	<c:if test="${indent.state==1 }">
          			<a href="toTaobaoUzIndentComplete?userIndent.id=${indent.id }" target="_self">手工完成</a><br/>
          		</c:if>
             </sec:authorize>
             <a href="toTaobaoUzIndentDetails?userIndent.id=${indent.id }" target="_self">详情</a><br/>
           </td>
    </tr>
	</c:forEach>
	
    

</tbody></table>
</div>
<!--pages-->
<div id="pagination" style="width:100%;float:left;padding-bottom:26px;"></div>
<!--pages-->
</form>
<div class="c"></div>
</div>
<script type="text/javascript" src="../js/global.js"></script>
<script type="text/javascript" src="../js/date.js"></script>
<script type="text/javascript">
    if (typeof (HTMLElement) != "undefined" && !window.opera) {
    HTMLElement.prototype.__defineGetter__("outerHTML", function () {
        var a = this.attributes, str = "<" + this.tagName, i = 0; for (; i < a.length; i++)
            if (a[i].specified)
                str += " " + a[i].name + '="' + a[i].value + '"';
        if (!this.canHaveChildren)
            return str + " />";
        return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });
    HTMLElement.prototype.__defineSetter__("outerHTML", function (s) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df = r.createContextualFragment(s);
        this.parentNode.replaceChild(df, this);
        return s;
    });
    HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
    });
}
if (typeof (HTMLElement) != "undefined" && !window.opera) {
    HTMLElement.prototype.__defineGetter__("outerHTML", function () {
        var a = this.attributes, str = "<" + this.tagName, i = 0; for (; i < a.length; i++)
            if (a[i].specified)
                str += " " + a[i].name + '="' + a[i].value + '"';
        if (!this.canHaveChildren)
            return str + " />";
        return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });
    HTMLElement.prototype.__defineSetter__("outerHTML", function (s) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df = r.createContextualFragment(s);
        this.parentNode.replaceChild(df, this);
        return s;
    });
    HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
    });
}
</script>
<script type="text/javascript">
    var valueControls={//能直接用 obj.value赋值的控件名及Type
        "input":"text,password,hidden",
        "select":"select-one",
        "textarea":"textarea"
    };
    
    var formData={};
	//formData["qe.productCode"]="";
	//formData["qe.billStartMoney"]="";
	//formData["qe.billInfo"]="";
	//formData["qe.billInfoSimple"]="";
	//formData["qe.billEndMoney"]="";
	//formData["qe.status"]="";
	//formData["qe.statusSimple"]="";
	//formData["qe.userAccount"]="";
    for(var id in formData){//铺数据
      var obj=document.getElementById(id);
      if(id && obj){//checkBox
        var tagName=obj.tagName.toLowerCase();
        if(obj.type){
          var type=obj.type.toLowerCase();
          if(valueControls[tagName] && valueControls[tagName].indexOf(type)!=-1){
            if(eval("document.getElementById(\""+id+"\")")){
              document.getElementById(id).value=formData[id];
            }
          }else{
             if(type=="radio" || type=="checkbox"){
              initRadioOrCheckBox(id); 
             }
             if(type=="select-multiple"){
              initMultiSelect(id);
             }
          }
        }else{
           obj.innerHTML=formData[id]; 
        }
      }
    }
    function initRadioOrCheckBox(id){
      var servingTimes=document.getElementsByName(id);
      for(var s=0;s<servingTimes.length;s++){
         if(servingTimes[s].type=="checkbox")
           servingTimes[s].checked=false;
      }
      if(formData[id]){
        var servingTimesValue=formData[id].split(",");
        for(var s=0;s<servingTimesValue.length;s++){
         for(var i=0;i<servingTimes.length;i++){
            if(servingTimes[i].value==servingTimesValue[s].trim())
            servingTimes[i].checked=true;
         }
       }
      }else{
       for(var i=0;i<servingTimes.length;i++){
         if(servingTimes[i].type=="checkbox")
           servingTimes[i].checked=true;
       }
      }
   }
   function initMultiSelect(id){
      var selOptions=document.getElementById(id).options;
      for( var i=0;i<selOptions.length;i++){
         selOptions.selected=false;
      }
      if(formData[id]){
        var selOptionsValue=formData[id].split(",");
        for(var s=0;s<selOptionsValue.length;s++){

         for(var i=0;i<selOptions.length;i++){
            if(selOptions[i].value==selOptionsValue[s].trim())
            selOptions[i].selected=true;
         }
       }
      }else{
       for(var i=0;i<selOptions.length;i++){
         selOptions[i].selected=false;
       }
      }
   }
</script>    
<script type="text/javascript">
function getQueryString(form,param) {
        var datastring = '';
        var inputs = form.getElementsByTagName('INPUT');
        for (var i = 0; i < inputs.length; i++) {
            if(inputs[i].name==param)continue;
            
            switch (inputs[i].getAttribute('type')) {
                case 'text':
                    datastring = plamostr(inputs[i], datastring);
                    break;
                case 'hidden':
                    datastring = plamostr(inputs[i], datastring);
                    break;
                case 'checkbox':
                    if (inputs[i].checked) {
                        datastring = plamostr(inputs[i], datastring);
                    }
                    break;
                case 'radio':
                    if (inputs[i].checked) {

                        datastring = plamostr(inputs[i], datastring);
                    }
                    break;
            }
        }
        var textareas = form.getElementsByTagName('TEXTAREA');
        for (var i = 0; i < textareas.length; i++) {
            datastring = plamostr(textareas[i], datastring);
        }
        var selectes = form.getElementsByTagName('SELECT');
        for (var i = 0; i < selectes.length; i++) {
            datastring = plamostr(selectes[i], datastring);
        }
        if(param){
            document.getElementById(param).value=datastring;
        }
        return datastring;
    }
    function plamostr(object, datastring) {
        /**
         *拼装Form数据字符串
         */
        if (datastring.length > 0) {
            datastring += '&' + object.getAttribute('name') + '=' + object.value;
        } else {
            datastring += object.getAttribute('name') + '=' + object.value;
        }
        return datastring;
    }
</script><script type="text/javascript">
if(parent.adminNavClass){
  parent.adminNavClass.initTips();
}
</script>
<script type="text/javascript">
function showConfirm(info,href){
 info = info ;//+ "<br>操作理由：<input type='text' id='____operationReason'><br>操作密匙：<input type='text' id='____operationPassword'>";
 showDialog({type:"confirm",message:info,onOk:function(){
   //var ____operationReason=document.getElementById("____operationReason").value;
   //if(!____operationReason || ____operationReason==""){alert("请输入操作理由");return false;}
   location.href=href;
   //openNewUrl('user'+new Date().getTime(),info,href);
   return true;
 }});
}
var operations=document.getElementsByTagName("a");
for(var i=0;i<operations.length;i++){
    var obj=operations[i];
    var confirm=obj.getAttribute("confirm");
    if(!confirm || confirm!="yes")continue;
    obj.onclick=function(e){
        e=window.event||e;
        var el=e.srcElement;
        if(!el.getAttribute("confirmurl")){
		   el.setAttribute("confirmurl",el.href);
		   el.href="javascript:void(0);";
		};
        showConfirm("确认执行"+el.innerText+"操作？！",el.getAttribute("confirmurl"));
        return false;
    }
}

var allInputs = document.getElementsByTagName('input');
if(allInputs && allInputs.length>0){
	for(var i=0; i<allInputs.length;i++)
	{
		var ipt = allInputs[i].parentNode;
		if(ipt.tagName=='LI'&& allInputs[i].type=='radio')
		{
			allInputs[i].checked && (ipt.className='current');
			ipt.onclick = function(){radioWithWords(this)};
		}
	}
}
var currentPage = ${pageNum};
var totalPage = ${paginationSupport.pageNum};
var recordPerPage = ${paginationSupport.pageSize};
var totalRecord = ${paginationSupport.totalCount};
var turnToPath = "";
if(totalPage<1) totalPage=1;
turnToPath = $('#queryForm').attr('action');
queryString = $('#queryString').val();
var pagination = new Pagination(currentPage, totalPage, recordPerPage, totalRecord, turnToPath, queryString);
pagination.initPagination();
var str = "${baseIndentType.url2 }&pageNum=" + currentPage +"&"+queryString;
document.getElementById("state_${current}").className="current";
</script>
<sec:authorize ifAnyGranted="ROLE_ROOT,ROLE_ADMIN,ROLE_AUDIT">
	<c:if test="${current=='0' || current=='1'  }">
		<script>
		$(".con_menu").click(function(){
				var c = $(this).attr("c");
				if(c=="1"){
					$(this).removeClass("c1");
					$(this).addClass("tr1");
					$(this).attr("c","0");
				}else if(c=="0"){
					$(this).addClass("c1");
					$(this).removeClass("tr1");
					$(this).attr("c","1");
				}
		});
		
		$(".con_menu").contextMenu('myMenu1', 
			     {
			          bindings: 
			          {
			            'checkAll': function(t) {
			              var flag = false;
			              $(".con_menu").each(function(i,val){
			            	  flag = $(val).hasClass("c1");
			            	  if(!flag){
			            		  return false;
			            	  }
			              });
			              
			              if(flag){
			            	  $(".con_menu").each(function(i,val){
			            		  $(val).removeClass("c1");
			            		  $(val).addClass("tr1");
			  					  $(val).attr("c","0");
			            	  });
			              }else{
			            	  $(".con_menu").each(function(i,val){
			            		  $(val).addClass("c1");
			            		  $(val).removeClass("tr1");
			  					  $(val).attr("c","1");
			            	  });
			              }
			              
			            }
			          }
			    });
		
		
		</script>
	</c:if>
</sec:authorize>
<div class="contextMenu" id="myMenu1">
      <ul>
        <li id="checkAll">全选/反选</li>
      </ul>
    </div>
</body></html>
